/**
 * 
 */
package pa2;

import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.Registry;
import java.util.Random;

import tests.TestCase1;
import tests.TestCase2;
import tests.TestCase3;
import tests.TestCase4;

/**
 * @author Joerg Poecher
 * 
 */
public class MyKVClient {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		String host = "localhost";
		String port = Integer.toString(Registry.REGISTRY_PORT);
		IMyKVPeer[] peers = new IMyKVPeer[4];

		System.out.println("Looking up MyKVPeers at " + host + ":" + port);

		try {
			// testing if all are available...
			for (int i = 0; i < IMyKVPeer.NUM_OF_PEERS; i++) {
				peers[i] = (IMyKVPeer) Naming.lookup("//" + host + ":" + port
						+ "/" + IMyKVPeer.SERVICENAME + i);
				System.out.println("Peer Nummer: " + peers[i].getPeerNumber());
				System.out.println(peers[i].say());
			}
			
			
			// TestCase1: Plot the histogram of the lookup latency for a random key
			// (when the data structure is empty).
			new TestCase1(peers).startTest();
			
			// TestCase2: Plot the histogram of the insert latency for a random key
			// (when the data structure is empty).
			new TestCase2(peers).startTest();
			
			// TestCase3: Histogram of storage right after 1000 random keys have been 
			// inserted. (1 key already inserted with TestCase2)
			new TestCase3(peers).startTest();

			// TestCase4: Histogram of message overhead for a random lookup right after
			// 1000 random keys have been inserted.
			new TestCase4(peers).startTest();
			

		} catch (MalformedURLException e) {
			System.out.println("Probleme mit der RMI URL...");
			e.printStackTrace();
		} catch (RemoteException e) {
			System.out.println("Probleme mit dem RMI Objekt...");
			e.printStackTrace();
		} catch (NotBoundException e) {
			System.out.println("RMI Objekt nicht gebunden...");
			e.printStackTrace();
		}
	}
}
